export default {
  data () {
    return {
      ispassword: true,
      LoginuserInfo: {
        username: '',
        password: ''
      },
      loginRules: {
        username: [
          { required: true, message: '请输入登陆名', trigger: 'blur' },
          { min: 5, max: 15, message: '长度在 5 到 15 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不规范', trigger: 'blur' },
          { min: 3, max: 8, message: '长度在 3 到 8 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    reseForm () {
      this.$refs.loginForm.resetFields()
    },
    islogin () {
      this.$refs.loginForm.validate(async result => {
        // 验证失败直接 return
        if (!result) return
        const {data: res} = await this.$http.post('login', this.LoginuserInfo).catch(err => err)
        // 登录失败
        console.log(res)
        if (res.meta.status !== 200) return this.$message.error('账号或密码错误!')
        // 把信息存入session
        sessionStorage.setItem('login', res.data.token)
        // 登录成功,跳转
        this.$router.push('/home')
      })
    }
  }
}
